Repository navigation
fix(maths): correct decimal isolation regex and add boundary tests (R50-T032) - #70
Open
nishadaniket174 wants to merge 1 commit into
Open
nishadaniket174 wants to merge 1 commit into
nishadaniket174 wants to merge 1 commit into
Conversation
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an issue in the
decimalIsolate()function inMaths/DecimalIsolate.js.The original regular expression did not correctly identify the decimal point, which caused incorrect results for certain inputs, particularly single-digit integers.
The implementation has been updated to correctly isolate the fractional part of a number and return
0when there is no decimal part or when the number is outside the supported format.What has changed?
Fixed the regular expression to match the decimal point correctly.
Added a check to handle numbers without a decimal point.
Improved the function documentation to explain its supported input range and expected behavior.
Added tests covering normal inputs, boundary values, negative numbers, integers, and unsupported exponential notation.
Test cases covered
Input | Expected result -- | -- 12.34 | 0.34 -1.2 | 0.2 0.5 | 0.5 0.000001 | 0.000001 -0.000001 | 0.000001 1.000001 | 0.000001 0, 1, 10 | 0 1e-7, 1e21 | 0Testing and verification
Initially reproduced the bug with a failing test for input
1.All 11 focused tests passed after the fix.
Full repository test suite passed: 11,981 tests.
Prettier formatting and
npm run check-stylepassed.Files changed
Maths/DecimalIsolate.jsMaths/test/DecimalIsolate.test.jswork/R50-T032/WORK_LOG.mdwork/R50-T032/check.pyTask: R50-T032
This change fixes the incorrect decimal extraction behavior and adds tests to help prevent the same issue from returning in the future.